import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {ApiProvider} from "../../providers/api/api";

/**
 * Generated class for the AllRankingPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-all-ranking',
  templateUrl: 'all-ranking.html',
})
export class AllRankingPage {
  class_course_id;
  allRankingList;
  serverPort;
  constructor(public navCtrl: NavController, public navParams: NavParams,public http:ApiProvider) {
  }

  ionViewDidEnter()
  {
    this.class_course_id=this.navParams.get("class_course_id");
    this.serverPort=this.http.filePath;

    this.showAllRanking();
  }

  /**
   * 显示全部班级排序
   */
  showAllRanking()
  {
    this.http.post("/userstu/allRank.do",{class_course_id:this.class_course_id}).subscribe(item=>{
      if(item["Code"]=="11111111")
      {
        this.http.showToast(item["Message"],'bottom');
      }
      else
      {
        this.allRankingList=item["rankList"];
        console.log(this.allRankingList);
      }
    });
  }

  /**
   * 下拉刷新
   * @param refresher
   */
  doRefresh(refresher)
  {
    this.http.post("/userstu/allRank.do",{class_course_id:this.class_course_id}).subscribe(item=>{
      if(item["Code"]=="11111111")
      {
        this.http.showToast(item["Message"],'bottom');
      }
      else
      {
        setTimeout(() => {
          this.allRankingList=item["rankList"];
          refresher.complete();
        },2000);
      }
    });
  }
}
